package com.ymatou.iapi.refund.testcase;

import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.refund.parameter.GetReturnReasonsV2Bean;
import com.ymatou.iapi.refund.parameter.GetReturnReasonsV2Resp;
import com.ymatou.iapi.refund.parameter.ReturnReason;
import com.ymatou.iapi.refund.service.GetReturnReasonsV2Call;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.database.model.CS_ReturnApplyReason;
import com.ymttest.database.sqlwapper.CS_ReturnApplyReasonWapper;
/**
*获取最大可退金额
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_GetReturnReasonsV2{
	private static GetReturnReasonsV2Bean bean;
	private static GetReturnReasonsV2Call call;
	private static CS_ReturnApplyReasonWapper reasonWapper=new CS_ReturnApplyReasonWapper();;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("获取退货原因");
	}

	@Before
	public void caseUp() {
		bean=new GetReturnReasonsV2Bean();
		call=new GetReturnReasonsV2Call();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(call.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetReturnReasonsV2_001() {
		Logger.start(true,"正例-获取退货原因");
		try {
			bean.setOrderStatus(0);
			call.setData(bean);
			call.callService();			
			verifyReturn();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetReturnReasonsV2_002() {
		Logger.start(true,"正例-获取退货原因-类型等于1");
		try {
			bean.setOrderStatus(1);
			call.setData(bean);
			call.callService();			
			verifyReturn();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetReturnReasonsV2_003() {
		Logger.start(true,"正例-获取退货原因-类型不存在");
		try {
			bean.setOrderStatus(999999);
			call.setData(bean);
			call.callService();			
			verifyReturn();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	private void verifyReturn()
	{
		Logger.verifyEquals("",call.getMsg1(), "验证Msg");
		Logger.verifyEquals("200",call.getStatus(), "验证Status");
		Logger.verifyEquals("0",call.getbCode(), "验证bCode");
		
		List<CS_ReturnApplyReason> reasonList=reasonWapper.getListByType(bean.getOrderStatus());
		List<ReturnReason> respList=call.getCallData().getRetData();
		Logger.verifyEquals(respList.size(),reasonList.size(), "验证返回的数据与数据库数量一致");
		
		for(int i=0;i<reasonList.size();i++)
		{
			Logger.verifyEquals(respList.get(i).getSubReasonId(),reasonList.get(i).getReturnReasonId(), "验证数据库CS_ReturnApplyReason第"+(i+1)+"个字段SubReasonId是否正确");
			Logger.verifyEquals(respList.get(i).getReasonDescrip(),reasonList.get(i).getTitle(), "验证数据库CS_ReturnApplyReason第"+(i+1)+"个字段Title是否正确");
			Logger.verifyEquals(respList.get(i).getIsYmtHandel(),reasonList.get(i).getNeedYmtHd()==0?false:true, "验证数据库CS_ReturnApplyReason第"+(i+1)+"个字段NeedYmtHd是否正确");
			
		}
	}
}